<?php

abstract class Engine_View_Element_ActionBar {

    /**
     * action format
     * [link] - href
     * [name] - item name
     * [icon] - icon
     * [label] - label
     * [type] - button or a
     */
    protected $items = array();

    public function __construct() {
        $this->init();
    }

    abstract function init();

    public function addAction($name, array $action) {
        $this->items[$name] = $action;
    }

    public function removeAction($name)
    {
        unset($this->items[$name]);
    }

    public function renderActions() {
        $result = '';
        foreach ($this->items as $item)
        {
            if ($item == 'separator') {
            $result .= '<hr class="win-command">';
            }   else  {
            $href = array_key_exists('link', $item) ? $item['link'] : false;
            $href = $href ? ' href="' . $href . '" ' : '';

            $result .= '<' . $item['type'] . ' class="win-command" ' . $href . '>';
            $result .= '<span class="win-commandimage win-commandring">' . $item['icon'] . '</span>';
            $result .= '<span class="win-label">' . $item['label'] . '</span>';
            $result .= '</' . $item['type'] . '>';
            }
        }
        return $result;
    }

    public function addSeparator($name) {
        $this->items[$name] = 'separator';
    }

    public function render() {

        $result = '';
        $result .= '<footer class="win-commandlayout navbar-fixed-bottom win-ui-dark">';
        $result .= '<div class="container">';
        $result .= '<div class="row">';
        $result .= $this->renderActions();
        $result .= '</div>';
        $result .= '</div>';
        $result .= '</footer>';

        return $result;
    }

}